﻿@{
    ViewBag.Title = "校园简介";
}
<div class="title-content">校园简介</div>
<div>
    <link href="../../Scripts/ueditor/themes/default/css/ueditor.css" rel="stylesheet" />
    <script src="../../Scripts/ueditor/third-party/jquery-1.10.2.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Scripts/ueditor/ueditor.config.js"></script>
    <script src="../../Scripts/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" charset="utf-8" src="../../Scripts/ueditor/ueditor.all.min.js"></script>

    <div class="form-group">
        <input class="form-control form-control-solid placeholder-no-fix" type="text" placeholder="设置标题" id="title" style="width:400px;" />
    </div>

    <div>设置幼儿园简介：</div>
    <div>
        <!--style给定宽度可以影响编辑器的最终宽度-->
        <script type="text/plain" id="myEditor" style="width:1000px;height:370px;"></script>
        <div style="margin-top:10px;text-align:center;width:1000px;">
            <button type="button" class="btn green" onclick="save()">保存</button>
        </div>
    </div>
    <script type="text/javascript">
        //实例化编辑器
        window.UEDITOR_HOME_URL = "/Scripts/ueditor/";
        var um = UE.getEditor('myEditor', {
            toolbars: [[
                'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'simpleupload', 'insertimage'
            ]]
        });
        function save() {
            var title = $("#title").val().trim();
            var text = UE.getEditor('myEditor').getContentTxt();//纯文本
            if (title == "") {
                AlertMsg("幼儿园名称不能为空");
                $("#title").focus();
                return;
            }
            if (text == "") {
                AlertMsg("简介不能为空");
                UE.getEditor('myEditor').focus();
                return;
            }
            var html = UE.getEditor('myEditor').getContent();
            //进行base64编码
            var str = CryptoJS.enc.Utf8.parse(html);
            var contentBM = CryptoJS.enc.Base64.stringify(str);
            //var contentBM = //escape(html); //encodeURI(html);// decodeURI(html);
            AjaxCustom({
                url: "/School/UpdateSchool",
                type: "post",
                parames: { title: title, content: contentBM },
                callBack: function (data) {
                    if (data.code == "1") {
                        AlertMsg("保存成功");
                    }
                }
            });
        }

        window.onload = function () {
            $("#title").focus();
            //UM.getEditor('myEditor').focus(); //编辑器获得焦点
            //显示校园简介
            AjaxCustom({
                url: "/School/getSchoolInfo",
                type: "post",
                callBack: function (obj) {
                    $("#title").val(obj.data[0].schoolName);
                    UE.getEditor('myEditor').setContent(obj.data[0].schoolIntroduce)
                }
            });
        }
    </script>
</div>
